<#assign module="member"/>

<@override name="header">
<link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
</@override>
<@override name="body">
<div class="row">
	<div class="col-xs-12">
	    <div class="orders-navt col-xs-9" style="padding-left:0">
	   		<ul class="orders-nav">
	  			<li class="orders-notclick " style="width:90px;"><a class="tab" href="${ctx}/member/list">所有用户</a></li>
		  		<li class="orders-notclick" style="width:90px;"><a class="tab" href="${ctx}/member/elist">企业信息</a></li>
		  		<li class="orders-notclick" style="width:90px;"><a class="tab" href="${ctx}/member/gradelist">用户等级</a></li>
		  		<li class="orders-notclick" style="width:90px;"><a class="tab" href="${ctx}/member/lock">登录记录</a></li>
		  		<@shiro.hasPermission name='blacklist'>
		  			<li class="orders-notclick" style="width:90px;"><a class="tab" href="${ctx}/member/blacklist">黑名单</a></li>
		  		</@shiro.hasPermission>
		  		<@shiro.hasPermission name='phonevisit'>
		  			<li class="orders-notclick" style="width:90px;"><a class="tab" href="${ctx}/phonevisit/list">回访记录</a></li>
		  		</@shiro.hasPermission>
		  		<@shiro.isMainCompany>
				  <@shiro.hasPermission name='memberapply'>
				  	<#--
				  	<li class="orders-notclick" style="width:90px;"><a class="tab" href="${ctx}/memberapply/list">VIP申请</a></li>
				  	-->
				  </@shiro.hasPermission>
			  	</@shiro.isMainCompany>
			  	<@shiro.hasPermission name='receipt'>
			  		<li class="orders-click" style="width:90px;"><a class="tab" href="${ctx}/receipt/list">发票申请</a></li>
			   	</@shiro.hasPermission>
			   	<@shiro.hasPermission name='membernotice'>
			   		<li class="orders-notclick" ><a class="tab" href="${ctx}/membernotice/list">通知</a></li>
			   	</@shiro.hasPermission>
		    </ul>
		</div>
		<div class="col-xs-3" style="padding:0;">
			<button class="pull-right btn btn-primary" onclick="window.location='${ctx}/receipt/toAdd';">&nbsp;开发票</button>
  		</div>
	</div>
  	
</div>


<div class="tab-content">
	<div class="container-fluid ">
  		<div class="row query-pad">
  			<div class="col-xs-11" style="padding: 0px;">
      			<div class="col-xs-4 input-query">
        			<span>发票编号：</span>
        			<input type="text" class="form-control form-contb" id="number" name="number"  placeholder="请输入发票编号">
        		</div>
        		<div class="col-xs-4 input-query">
  						<span>会员名称：</span>
						<input type="text" class="form-control form-contb" id="name" placeholder="输入会员名称">
            	</div>
            	<div class="col-xs-4 input-query">
            			<span>会员电话：</span>	
						<input type="text" class="form-control form-contb" id="phone" placeholder="输入会员电话">
				</div>
    		</div>
    		<div class="col-xs-1"style="padding: 0px;">
    			<div class="input-query-bttom">
        			<button id="searchButton" class="btn btn-primary">&nbsp;查询</button>
        		</div>
    		</div>
  		</div>
  		
  		<div class="choose" style="display: none;">
  				<div class="col-xs-11" style="padding: 5px;">
					<div class="col-xs-4 input-query" style="text-align: center;">
					<span>发票申请时间：</span>	
					<input type="text" style="" class="form-control form-conthtl"  id="startTime" name="startTime" placeholder="请输入开始时间"">
					<span>到</span>
					<input type="text" class="form-control form-conthtl"  id="endTime" name="endTime" placeholder="请输入结束时间" >
				</div>
            	</div>
  		</div>
  	 <div class="col-xs-12">	
  		<div class="query-jiant">
			<a href="#"><img id="jiant" src="${ctx}/assets/img/jiant2.png" /></a>          			
  		</div>
  	 </div>	
  	</div>
</div>

<div class="tabta-content">  	
	<table class="table table-condensed table-striped">
		<tbody>
		<tr>
			<th style='min-width:120px;'>发票编号</th>
			<th style='min-width:120px;'>会员名称</th>
			<th style='min-width:120px;'>会员电话</th>
			<th style='min-width:120px;'>发票额度</th>
			<th style='min-width:120px;'>状态</th>
			<th style='min-width:120px;'>类型</th>
			<th style='min-width:240px;'>申请时间</th>
			<th style='min-width:240px;'>开票时间</th>
			<th style='min-width:120px;'>客户备注</th>
			<th style='min-width:120px;'>开票备注</th>
			<th style='min-width:8px;'>操作</th>
		</tr>
		</tbody>
	</table>
	<br>
	<div style="text-align:center" id="NoData"></div>
	</br>
	<ul class="pagination pull-left pagination-sm pageshow" style="display:none;">
		<li><a></a></li>
	</ul>
	<ul class="pagination pull-left pagination-sm pagedata" style="display:none;">
    </ul>
</div>


<!--开发票-->
<div class="form-horizontal">
	<div class="modal fade" id="dialog_modifyCash">
	  <div class="modal-dialog">
	    <div class="modal-content">
	    	<div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		        <h4 class="modal-title">审核发票</h4>
		      </div>
		    <div class="modal-body">
	      	<form action="${ctx}/receipt/billing"  method="post">
	      		<input type="hidden" id="receiptId" name="id"  />
	      		
		      	<div class="form-group">
	      	 		<label class="col-sm-3 control-label">发票编号：</label>
                    <div class="col-sm-8">
                    	<input  class="form-control" name="number" maxlength="15" type="text"  placeholder="选填" />
                    </div>
		        </div>
		         <div class="form-group">
                    <label class="col-sm-3 control-label">开票备注：</label>
                    <div class="col-sm-8">
                    	<textarea class="form-control" cols="60" name="billingDesc" rows="3" placeholder="选填" ></textarea>
                    </div>
				 </div>
				   <div class="form-group">
                 	  <div class="col-sm-6">
                	  </div>
                	  <div class="col-sm-3">
					      <input  type="submit" class="btn btn-primary" value="确定">
					      <button type="button" class="btn btn-default" id="close_modal_memo">关闭</button>
		        	  </div>
		           </div>  
		  	</form>
	     </div>
	     </div>
	  </div>
	</div>
</div>

</@override>
<@override name="footer">
<script type="text/javascript">
		window.daijia = {
			ctx:'${ctx}',
			userId:'<@shiro.principal property='id'/>'
		};
	</script>
<script src="${ctx}/assets/js/pushmessage.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.min.js"></script>
<script src="${ctx}/assets/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${ctx}/assets/js/jquery.paging.min.js"></script>
<script type="text/javascript">
var offset=0;
var limit=20;
var pagingLimit=20;//显示分页时的条数
var currentTotalElements=0;//当前显示总条数

var pageLoading=true;//是否能滚动加载
var hasShowPages=false;//是否已显示分页
var firstLoadPages=true;//分页初始化时 不自动加载

var search_name=null;
var search_phone=null;
var search_number=null;
var search_endTime=null;
var search_startTime=null;

$(document).ready(function(){
	
		$("#startTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
		$("#endTime").datetimepicker({ format: 'yyyy-mm-dd', language: 'zh-CN', minView: 'month', pickDate: true, pickTime: false, inputMask: false, autoclose: true });
	$(window).scroll(function () {
	    //$(window).scrollTop()这个方法是当前滚动条滚动的距离
	    //$(window).height()获取当前窗体的高度
	    //$(document).height()获取当前文档的高度
	    var bot = 0; //bot是底部距离的高度
	    if ((bot + $(window).scrollTop()) >= ($(document).height() - $(window).height())) {
	       //当底部基本距离+滚动的高度〉=文档的高度-窗体的高度时；
	    	if(pageLoading){
	    		pageLoading=false;
	    		offset+=limit;
	    		initdata(true);
	    	}
	    }
	});
	
	$(document).on("keydown","body",function(){
		if(window.event.keyCode == 13){
			$("#searchButton").click();
		}
	});


$("#searchButton").click(function(){
		
		var DATE_FORMAT = /^[0-9]{4}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1}$/;
		if($("#startTime").val()!=""){
			if(!DATE_FORMAT.test($("#startTime").val())){
			   $.scojs_message("您输入的启始日期格式有误，正确格式如：2012-01-01", $.scojs_message.TYPE_ERROR);
			   return false;
			}
		}
		
		if($("#endTime").val()!=""){
			if(!DATE_FORMAT.test($("#endTime").val())){
				$.scojs_message("您输入的结束日期格式有误，正确格式如：2012-01-01", $.scojs_message.TYPE_ERROR);
				return false;
			}
		}
		
		if($("#startTime").val()!="" && $("#endTime").val()!=""){
			if($("#startTime").val()>$("#endTime").val()){
				 $.scojs_message("启始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
				 return false;
			}
		}
		search_name=$("#name").val();
		search_startTime=$("#startTime").val();
		search_endTime=$("#endTime").val();
		search_phone=$("#phone").val();
		search_number=$("#number").val();
		offset=0;
		initdata(false);
		
	});
initdata(false);


});

	var thisButton;
	function deleteReceipt() {
	    $.post('${ctx}/receipt/delete',{'id':thisButton.attr("data-value")},function(data){
	            if(data.success){
	            	thisButton.parent().parent().remove();
	                $.scojs_message("删除发票成功", $.scojs_message.TYPE_OK);
	                 setTimeout(function(){
	     					window.location.reload(true);
	     			}, 1000);
	            }else{
	                $.scojs_message("删除发票失败!", $.scojs_message.TYPE_ERROR);
	            }
	    },'json');
	}
	$(document).ready(function(){
	
	    $(document).on("click",".deletethis",function(){
	          thisButton = $(this);
	          var confirm = $.scojs_confirm({
	            content: "你真的要删除该发票吗？删除后开票额度将增加到客户消费金额上用于下次开票",
	            action:deleteReceipt
	          });
	          confirm.show();
	    });
	});
  	$(document).on("click",".modifyCash",function(){
  			var  receiptId=$(this).attr('data-value');
  			$('#receiptId').val(receiptId);
	    	$('#dialog_modifyCash').modal();
    });
    $("#close_modal_memo").click(function(){
		$('#dialog_modifyCash').modal("hide");
	});
	
	$('#endTime').change(function(){
			  var begin=new Date($('#startTime').val().replace(/-/g,"/"));
		      var end=new Date($('#endTime').val().replace(/-/g,"/"));
		   	   if(begin!=null&&end!=null&&begin-end>=0){
	  				 $('#endTime').val("");
	  				 $.scojs_message("截止日期要在开始日期之后!", $.scojs_message.TYPE_ERROR);
		      	}
	 });
    $('#startTime').change(function(){
		  var begin=new Date($('#startTime').val().replace(/-/g,"/"));
	      var end=new Date($('#endTime').val().replace(/-/g,"/"));
	   	   if(begin!=null&&end!=null&&begin-end>=0){
  				 $('#endTime').val("");
  				 $.scojs_message("开始日期要在截止日期之前!", $.scojs_message.TYPE_ERROR);
	      	}
	 });
	 
//高级搜索
	$(".query-jiant").click(function(){
		var src=$("#jiant").attr("src");
		if(src.indexOf("jiant2")>=0){
			$("#jiant").attr("src",ctx+"/assets/img/jiant.png");
			$(".choose").show(300);
		}else{
			$("#jiant").attr("src",ctx+"/assets/img/jiant2.png");
			$(".choose").hide(300);
		}

		
	});
	function initdata(isappend){
	$.ajax({
        url : '/receipt/listData',
        type:'GET',
        async:false,
        dataType : 'json',
        data : {
        	"name":search_name,
        	"startTime":search_startTime,
        	"endTime":search_endTime,
        	"phone":search_phone,
        	"number":search_number,
        	"pager.offset":offset,
        	"limit":limit
        },
        success : function(result){
        	var newcontent = '';
        	$("#NoData").text("");
        	var totalElements=result.totalElements;
        	if(totalElements>0){
        		$(result.content).each(function(index,data){
        			var mainButton="";
        			var selectButton="";
        			var allButton="";
						if(data.status==0){
						   mainButton+="<a href='#'  class='modifyCash btn btn-primary btn-xs'  data-value='"+data.id+"' >开票</a>";
         		           selectButton+="<li><a href='javascript:;' data-value='"+data.id+"'  class='btn-link deletethis'>删除</a></li>";
         		          allButton+= "<div class='btn-group'>"+
            							mainButton+
									  "<button type='button' class='btn "+"btn-primary"+" btn-xs dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>"+
									    "<span class='caret'></span>"+
									    "<span class='sr-only'>Toggle Dropdown</span>"+
									  "</button>"+
									  "<ul class='dropdown-menu' role='menu'>"+
									  	selectButton+
									  "</ul>"+
									"</div>";
						}else{
						   mainButton+="<a href='javascript:;'  class='btn btn-primary btn-xs' style='width:62px;'>已开</a>";
						   allButton+="<div class='btn-group'>"+
            							mainButton+ "</div>";
						}         		   

            		
            		
            		
            		var status="";
            		if(data.status==0){
            		   status = "<span style='color:red;font-weight:700;'>未开</span>"
            		}else{
            		   status="<span style='color:green;font-weight:700;'>已开</span>";
            		}
            		
            		
	    newcontent+="<tr class='grid-data tr-hui' style='display:none;'>"+
						"<td>"+(data.number==null?"-":data.number)+"</td>"+
						"<td>"+data.memberName+"</td>"+
						"<td>"+data.memberPhone+"</td>"+
						"<td>"+data.money+"</td>"+
						"<td>"+status+"</td>"+
						"<td>"+data.type+"</td>"+
						"<td>"+new Date(data.created).Format("yyyy-MM-dd hh:mm:ss")+"</td>"+
						"<td>"+(data.billingDate==null?"暂未开票":new Date(data.billingDate).Format("yyyy-MM-dd hh:mm:ss"))+"</td>"+
						"<td>"+((data.memo==null)?"-":data.memo)+"</td>"+
						"<td>"+(data.billingDesc==null?"-":data.billingDesc)+"</td>"+
						"<td>"+allButton+"</td>"+
					"</tr>";
        		});
        	}
        	else{
              	 $("#NoData").text("当前页面暂无记录 ");
            }

//        	hideLoading();
        	
        	if(!isappend){
        		$(".table tbody .grid-data").remove();
        	}
        	
        	$(".table tbody").append(newcontent);
        	
        	$(".table tbody .grid-data").each(function(index,element){
        		$(element).fadeIn(200+(index*35));
        	});
        	
        	if(!hasShowPages){
        		if(!isappend){
            		currentTotalElements=result.numberOfElements;
            		pageLoading=true;
            	}
        		else{
            		if(currentTotalElements<totalElements){
            			currentTotalElements+=result.numberOfElements;
            			pageLoading=true;
            		}
            		else{
            			pageLoading=false;
            		}
            	}
        	}

        	if(hasShowPages){
    			firstLoadPages=true;
        		$(".pageshow li a").html("共"+totalElements+" 条数据");
        		$(".pagedata").paging(totalElements, {
        			format: '[< ncnnn >]',
        			perpage: pagingLimit,
        			page:(offset/limit)+1,
        			onSelect: function (page) {
        				limit=pagingLimit;
        				offset=(page-1)*limit;
        				if(!firstLoadPages){
        					initdata(false);
        				}
        				firstLoadPages=false;
        		    	return false;
        			},
        			onFormat: function (type) {
        				switch (type) {
        				case 'block': // n and c
        					if (!this.active)
        						return '';
        					else if (this.value != this.page)
        						return '<li><a href="#">' + this.value + '</a></li>';
        					return '<li class="active"><a href="#">' + this.value + '</a></li>';
        				case 'next': // >
        					return '<li><a href="#">&rsaquo;</a><li>';
        				case 'prev': // <
        						return '<li><a href="#">&lsaquo;</a><li>';
        				case 'first': // [
        						return '<li><a href="#">&laquo;</a><li>';
        				case 'last': // ]
        						return '<li><a href="#">&raquo;</a></li>';
        				}
        			}
        		});
        		
        	}
        	else{
        		//滚动达到pagingLimit条开始显示分页
        		if(currentTotalElements==pagingLimit){
            		
            		pageLoading=false;
            		hasShowPages=true;
            		
            		$(".pageshow").show();
            		$(".pagedata").show();
            		$(".pageshow li a").html("共"+totalElements+" 条数据");
            		$(".pagedata").paging(totalElements, {
            			format: '[< ncnnn >]',
            			perpage: pagingLimit,
            			onSelect: function (page) {
            				limit=pagingLimit;
            				offset=(page-1)*limit;
            				if(!firstLoadPages){
            					initdata(false);
            				}
            				firstLoadPages=false;
            		    	return false;
            			},
            			onFormat: function (type) {
            				switch (type) {
            				case 'block': // n and c
            					if (!this.active)
            						return '';
            					else if (this.value != this.page)
            						return '<li><a href="#">' + this.value + '</a></li>';
            					return '<li class="active"><a href="#">' + this.value + '</a></li>';
            				case 'next': // >
            					return '<li><a href="#">&rsaquo;</a><li>';
            				case 'prev': // <
            						return '<li><a href="#">&lsaquo;</a><li>';
            				case 'first': // [
            						return '<li><a href="#">&laquo;</a><li>';
            				case 'last': // ]
            						return '<li><a href="#">&raquo;</a></li>';
            				}
            			}
            		});
            		
            	}
        	}
        	
        }
	});
	
	
	
	
}

Date.prototype.Format = function(fmt) 
{ 
  var o = { 
    "M+" : this.getMonth()+1,                 //月份 
    "d+" : this.getDate(),                    //日 
    "h+" : this.getHours(),                   //小时 
    "m+" : this.getMinutes(),                 //分 
    "s+" : this.getSeconds(),                 //秒 
    "q+" : Math.floor((this.getMonth()+3)/3), //季度 
    "S"  : this.getMilliseconds()             //毫秒 
  }; 
  if(/(y+)/.test(fmt)) 
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
  for(var k in o) 
    if(new RegExp("("+ k +")").test(fmt)) 
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  return fmt; 
}	
	
</script>
</@override>
<@extends name="../layout.ftl"/>
